package cn.com.klun.tjy.admin.common;

import java.util.ArrayList;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractAdminController extends AbstractBaseController {
    protected Logger logger = LoggerFactory.getLogger("AbstractAdminController");
    protected String SUCCESS = "success";
    protected String ERROR = "error";
    protected String SAVE = "save";
    protected String EDIT = "edit";
    protected String DEL = "del";
    protected String QUERY = "query";
    protected String VIEW = "view";

    public AbstractAdminController() {
    }

    public boolean ajaxJsonMessage(HttpServletResponse response, String info) {
        return this.ajax(response, info, "text/html");
    }

    public boolean ajaxJsonMessage(HttpServletResponse response, String code, String message, String type) {
        JSONObject jo = new JSONObject();
        jo.put("code", code);
        jo.put("message", message);
        jo.put("type", type);
        return this.ajax(response, jo.toString(), "text/html");
    }

    public boolean ajaxJsonPage(String entity, int total, HttpServletResponse response) {
        String info = "";
        JSONObject jo;
        if (total == 0) {
            jo = new JSONObject();
            jo.put("code", this.ERROR);
            jo.put("total", Integer.valueOf(0));
            jo.put("rows", new ArrayList());
            jo.put("loadMsg", "系统异常，加载数据失败！");
            info = jo.toString();
        } else {
            jo = new JSONObject();
            jo.put("code", this.SUCCESS);
            jo.put("total", total);
            jo.put("rows", entity);
            info = jo.toString();
        }

        return this.ajax(response, info, "text/html");
    }
}
